<?php
/**
 * This file is part of Task Agile.
 * Task Agile is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 * Task Agile is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Task Agile.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category   TaskAgile
 * @package    Controller
 * @copyright  Copyright (c) 20010-2010 Estrada Virtual (http://estradavirtual.com.br)
 * @license    http://www.gnu.org/licenses/gpl.txt GPLv3
 * @version    $Id$
*/
/**
 * Model de TaskComment
 * @filesource  01/08/2010
 * @author      Estrada Virtual <http://estradavirtual.com.br>
 * @copyright   Copyright <2010> Estrada Virtual
 * @package     <<application>>
 * @subpackage  <<application>>.application.models
 * @version     $Id$
 */
class TaskComment extends Tev_Db_Table {
    const TYPE_USER        = 1;
    const TYPE_CLOSED      = 2;
    const TYPE_OPENED      = 3;
    const TYPE_FORWARD     = 4;
    const TYPE_INACTIVATED = 5;

    protected $_name = 'task_comment';
    protected $_referenceMap = array(
                    'Task' => array(
                            'columns'       => 'fk_task',
                            'refTableClass' => 'Task',
                            'refColumns'    => 'id',
                         ),
                    'User' => array(
                            'columns'       => 'fk_user',
                            'refTableClass' => 'User',
                            'refColumns'    => 'id',
                         ));

    /**
     *
     * Enter description here ...
     * @param $idTask
     * @param $idUser
     * @param $comment
     * @param $hours
     * @param $type
     * @return int value insert id
    */
     public function comment($idTask, $idUser, $comment, $hours = null, $type = null)
     {
         if (!$type) {
             $type = TaskComment::TYPE_USER;
         }
         $rowTaskComment = $this->createRow();
         $rowTaskComment->fk_task     = $idTask;
         $rowTaskComment->fk_user     = $idUser;
         $rowTaskComment->comment     = $comment;
         $rowTaskComment->dt_register = date('Y-m-d H:i:s');
         $rowTaskComment->type        = $type;
         $rowTaskComment->hours       = $hours;

         return $rowTaskComment->save();
     }
}
